﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;

namespace MyVocationSpace
{
    public partial class AddNewVocation : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BAL.conn.connectionString = ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString;

            if (Session["UserID"] == null)
            {
                Response.Redirect("Home.aspx");
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string vocName = txtVocation.Text;
            string Desc = txtDesc.Text;

            int IDTempVoc = BAL.Vocation.InsertTempVocation(Convert.ToInt32(Session["UserID"]), vocName, Desc);

            idSpanMsg.Style.Add("display", "block");
            idSpanMsg.InnerHtml = "Your request is Accepted and it will be confirmed by Admin and you will get notified soon";

            DataSet ds = BAL.Vocation.GetUserByTempVocation(IDTempVoc);

            if(ds.Tables.Count>0)
            {
                if(ds.Tables[0].Rows.Count>0)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        string content = "<div style=\"margin-left:20px;\">" +
                           "<span style=\"font-size: 12px; font-family: 'CENTURY GOTHIC'\">" +
                           "<br>New Vocation added by <b>" + dr["FirstName"].ToString() + " " + dr["LastName"].ToString() + "</b> with following details -<br>" +

                           "<br><b>Voaction Name:</b> " + txtVocation.Text + "<br>" +
                           "<br><b>Description:</b> " + txtDesc.Text + "<br>" +

                     "<br><br>Best Regards, <br><b>" + dr["FirstName"].ToString() + " " + dr["LastName"].ToString() +
                     "</span></div>";

                        string subject = "New Vocation Request Detail...";

                        BAL.Common.SendEmail("", ConfigurationManager.AppSettings["AdminID"].ToString(), subject, content);

                    }
                }
            }


            txtVocation.Text = "";
            txtDesc.Text = "";

        }
    }
}